{[j=20-/40/80!,o=95,a-]}					{ PasMat formatting options }

{Cameron Birse, Macintosh Technical Support}

PROGRAM RightModsOn;

{$U MyStuff}
USES
    Memtypes,QuickDraw,OSIntf,ToolIntf,PackIntf,MacPrint,Script,mystuff;
TYPE
    fourBytes = packed array [0..3] of byte;
VAR
    myStr,ADBData : str255;
    err,NumDevs,count			: Integer;
		  DevBlock	: ADBDataBlock;
    TheWorld : SysEnvRec;
    CompTrue,GotLEDs,gotADB : Boolean;
    Addrs,KyBdAddrs,CmdNum : signedByte;
    MyA5,R3Data : longint;
    ParseData : fourBytes;

	{------------------------------------------------------------------------------------}

PROCEDURE ADBCompTalk;
			
BEGIN
		
    PushA5;
    GetMyA5;
			 R3Data := GetADBData;
			 CompTrue := True;
			 PopA5;
			
END;

	{------------------------------------------------------------------------------------}
	
PROCEDURE ADBCompList;
			
BEGIN
		
    PushA5;
    GetMyA5;
			 CompTrue := True;
			 PopA5;
			
END;

	{------------------------------------------------------------------------------------}

FUNCTION    CompCheck:integer;
 
begin
    count := 0;
    CompCheck := 0;                 {assume no error}
    repeat
        count := count + 1;         {timeout check}
        if count = 10000 then
        begin
            CompCheck := count;       {My Timeout error code}
            comptrue := true;
        end
    until comptrue;
end;
	{------------------------------------------------------------------------------------}

BEGIN 							 {main PROGRAM}

    gotADB := false; {assume no ADB, and just exit if none}
    err:= SysEnvirons (1,TheWorld);
    if err = noerr then
    begin
        case theworld.machineType of
         0,3,4 : gotADB := True;
        end; {case}
    end
    else
    begin
        writeln ('SysEnvirons error = ',err);
        writeln ('Please press the mouse button to exit');
        repeat until button;
    end;
    If gotADB then
    BEGIN
        MyA5 := GetCurA5;
		      NumDevs := countADBs;
        KyBdAddrs := 0;
        GotLEDs := false;
 		     repeat
			         Addrs := GetIndADB (DevBlock, NumDevs);
			         Case DevBlock.origADBAddr of
			         2 : Begin
						              Case DevBlock.devType of 
						              1 : Begin
									                   GotLEDs := false;
								                end;
						              2 : Begin
									                   GotLEDs := true;
                            KyBdAddrs := Addrs;
								                end;
						              end; {case}
					           end;
			         end; {case}
            NumDevs := NumDevs - 1;
        Until (NumDevs = -1) or GotLEDs;
        if GotLeds then
        begin
			         Writeln ('Device = ',KyBdAddrs,' ; Device type = ',DevBlock.devType);
			         Writeln ('ADB Address = ',KyBdAddrs,' ; Original Address = ',DevBlock.origADBAddr);
            Writeln ('Routine Pointer = ',longint (DevBlock.dbServiceRtPtr),
                    ' ;Data Area Address = ',longint (DevBlock.dbDataAreaAddr));
			         writeln ('');
            CompTrue := false;
				 	      CmdNum := ((KyBdAddrs*16)+$0F);  {Device Address X, Talk command, Register 3}
						      ADBData[0] := Char($00);
						      ADBData[1] := Char($00);
						      ADBData[2] := Char($00);
						      err := ADBOp (@MyA5,@ADBCompTalk,@ADBData,CmdNum);
            if err = noerr then
            begin
                err := CompCheck;
                if err = noerr then
                begin
                    ParseData := fourBytes(R3Data);
                    writeln ('R3Data = ',ParseData[0],'-',ParseData[1],'-',ParseData[2]);
                end
                else Writeln ('Timeout error = ',err);
            end
            else Writeln ('ADBOp error = ',err);
            if err = noerr then
            begin
                CompTrue := false;
				 	          CmdNum := ((KyBdAddrs*16)+$0B);  {Device Address X, Listen command, Register 3}
						          ADBData[0] := Char(ParseData[0]);
						          ADBData[1] := Char(ParseData[1]);
						          ADBData[2] := Char($03);
						          err := ADBOp (@MyA5,@ADBCompList,@ADBData,CmdNum);
                if err = noerr then
                begin
                    err := CompCheck;
                end
                else Writeln ('ADBOp error = ',err);
            end;
            Writeln ('Press mouse to exit');
            repeat until button;
        end
        else
        begin
            Writeln ('No Extended Keyboard');
            Writeln ('Press mouse to exit');
            repeat until button;
        end;
    end;
End.